package cn.lingyangwl.agile.food.core.assembly;

import cn.lingyangwl.agile.model.BaseAssembly;
import cn.lingyangwl.agile.food.model.entity.Goods;
import cn.lingyangwl.agile.food.model.entity.GoodsCategory;
import cn.lingyangwl.agile.food.core.model.rqrs.cart.CartResp;
import cn.lingyangwl.agile.food.core.model.rqrs.goods.GoodsListResp;
import cn.lingyangwl.agile.food.model.rqrs.goods.GoodsResp;
import cn.lingyangwl.agile.food.model.rqrs.goods.GoodsSaveReq;
import cn.lingyangwl.agile.food.model.rqrs.goods.GoodsUpdateReq;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
 * 商品
 *
 * @author shenguangyang
 */
@Mapper(componentModel = "spring")
public interface GoodsAssembly extends BaseAssembly {

  @Mappings({
        @Mapping(source = "images", target = "images", qualifiedByName = STR_TO_LIST),
        @Mapping(source = "tenantIds", target = "tenantIds", qualifiedByName = JSON_STR_TO_SET),
        @Mapping(source = "goodsTypes", target = "goodsTypes", qualifiedByName = STR_TO_LIST),
  })
  GoodsResp toGoodsResp(Goods source);

  @Mappings({
      @Mapping(source = "images", target = "images", qualifiedByName = STR_TO_LIST),
      @Mapping(source = "tenantIds", target = "tenantIds", qualifiedByName = JSON_STR_TO_SET),
      @Mapping(source = "goodsTypes", target = "goodsTypes", qualifiedByName = STR_TO_LIST),
  })
  CartResp.Goods toCartGoodsResp(Goods source);

  @Mappings({
        @Mapping(source = "images", target = "images", qualifiedByName = LIST_TO_STR),
        @Mapping(source = "goodsTypes", target = "goodsTypes", qualifiedByName = LIST_TO_STR),
  })
  Goods toGoods(GoodsSaveReq source);

  @Mappings({
      @Mapping(source = "images", target = "images", qualifiedByName = LIST_TO_STR),
      @Mapping(source = "goodsTypes", target = "goodsTypes", qualifiedByName = LIST_TO_STR),
  })
  Goods toGoods(GoodsUpdateReq source);

  @Mappings({
          @Mapping(source = "id", target = "categoryId")
  })
  GoodsListResp toGoodsListResp(GoodsCategory source);
}
